/**
 *@Description: 登录store
 *@author: Wangsenyang
 *@Date: 2020/2/27
 */
import Vue from 'vue';
//  仅做示例
import api from '@/api';

const stateFactory = () => ({
    flowList: {
        nodeList: [],
        lineList: [],
    },
});

const initState = {
    ...stateFactory(),
};

const getters = {
    getFlowList(state) {
        return state.flowList;
    },
};

const actions = {

};

const mutations = {
    setResetFlow(state) {
        state.flowList = {
            nodeList: [],
            lineList: [],
        }
    },
    setFlowList(state, data) {
        state.flowList = { ...data }
    },
    setNodeName(state, data) {
        // 判断节点是否连接后是否有效 改变状态
        const index = state.flowList.nodeList.findIndex((item) => item.id === data.id);
        if (index > -1) {
            const node = state.flowList.nodeList[index];
            node.name = data.name;
            data.that.$set(state.flowList.nodeList, index, node);
        }
    },
};

export default {
    state: initState,
    actions,
    getters,
    mutations,
    namespaced: true,
};
